﻿package mortal.game.view.copy.groupCopy.view
{
    import Message.DB.Tables.*;
    import Message.Public.*;
    import com.gengine.resource.*;
    import com.mui.controls.*;
    import extend.language.*;
    import fl.data.*;
    import flash.events.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.pageSelect.*;
    import mortal.game.view.copy.groupCopy.data.*;
    import mortal.mvc.core.*;

    public class GroupCopyListPanel extends GroupCopyBaseListPanel
    {
        private var _groupsList:GTileList;
        private var _btnCreateCopy:GButton;
        private var _btnFastEnterGroup:GButton;
        private var _btnRefresh:GButton;
        private var _pageSelecter:PageSelecter;
        private var _sgroupMsg:SCopyWaitingGroupMsg;

        public function GroupCopyListPanel()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._btnCreateCopy = UIFactory.gButton("" + Language.getString(70901), 170, 296, 84, 27, this, "BrownBtn");
            this._btnCreateCopy.name = "GroupCopy_CreateTeamBtn";
            this._btnCreateCopy.configEventListener(MouseEvent.CLICK, this.clickHandler);
            this._btnFastEnterGroup = UIFactory.gButton("" + Language.getString(70902), 280, 296, 84, 27, this, "BrownBtn");
            this._btnFastEnterGroup.name = "GroupCopy_FastEnterGroup";
            this._btnFastEnterGroup.configEventListener(MouseEvent.CLICK, this.clickHandler);
            this._btnRefresh = UIFactory.gButton("" + Language.getString(70903), 42, 297, 55, 27, this);
            this._btnRefresh.configEventListener(MouseEvent.CLICK, this.clickHandler);
            this._groupsList = UIFactory.tileList(30, 62, 465, 255, this);
            this._groupsList.columnWidth = 460;
            this._groupsList.rowHeight = 45;
            this._groupsList.horizontalGap = 6;
            this._groupsList.verticalGap = 1;
            this._groupsList.setStyle("cellRenderer", GroupCopyTeamListRender);
            this._groupsList.isClickedUpdate = false;
            var _loc_1:* = GlobalStyle.textFormatBai.center();
            this._pageSelecter = UIFactory.pageSelecter(391, 299, this, PageSelecter.SingleMode);
            this._pageSelecter.setbgStlye(ImagesConst.ComboBg, _loc_1);
            this._pageSelecter.currentPage = 1;
            this._pageSelecter.pageTextBoxSize = 50;
            this._pageSelecter.configEventListener(Event.CHANGE, this.onPageChange);
            LoaderHelp.addResCallBack(ResFileConst.groupCopy, this.showSkin);
            this.updateBtnEnabled();
            NetDispatcher.addCmdListener(ServerCommand.GroupPlayerInfoChange, this.updateBtnEnabled);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            NetDispatcher.removeCmdListener(ServerCommand.GroupPlayerInfoChange, this.updateBtnEnabled);
            this._btnCreateCopy.name = "";
            this._btnFastEnterGroup.name = "";
            this._btnCreateCopy.dispose(param1);
            this._btnCreateCopy = null;
            this._btnFastEnterGroup.dispose(param1);
            this._btnFastEnterGroup = null;
            this._pageSelecter.dispose(param1);
            this._pageSelecter = null;
            this._groupsList.dispose(param1);
            this._groupsList = null;
            this._btnRefresh.dispose(param1);
            this._btnRefresh = null;
            super.disposeImpl(param1);
            return;
        }// end function

        private function showSkin() : void
        {
            if (isDisposed)
            {
                return;
            }
            this.pushUIToDisposeVec(UIFactory.gBitmap(ImagesConst.groupCopyTxt_8, 62, 42, this));
            this.pushUIToDisposeVec(UIFactory.gBitmap(ImagesConst.groupCopyTxt_10, 190, 42, this));
            this.pushUIToDisposeVec(UIFactory.gBitmap(ImagesConst.groupCopyTxt_6, 300, 42, this));
            this.pushUIToDisposeVec(UIFactory.gBitmap(ImagesConst.groupCopyTxt_5, 435, 42, this));
            return;
        }// end function

        private function onPageChange(event:Event) : void
        {
            this.getCopyGroupList();
            return;
        }// end function

        private function getCopyGroupList() : void
        {
            var _loc_1:* = new Object();
            _loc_1.code = _tcopy.code;
            _loc_1.page = this._pageSelecter.currentPage;
            Dispatcher.dispatchEvent(new DataEvent(EventName.GroupCopyListGet, _loc_1));
            return;
        }// end function

        private function createGroup(param1:int) : void
        {
            if (param1 == Alert.OK)
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.CopyGroupCreate, _tcopy));
                Dispatcher.dispatchEvent(new DataEvent(EventName.ArenaCancelSignUp));
            }
            return;
        }// end function

        private function fastEnterCopy(param1:int) : void
        {
            if (param1 == Alert.OK)
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.CopyGroupQuickReq, _tcopy));
                Dispatcher.dispatchEvent(new DataEvent(EventName.ArenaCancelSignUp));
            }
            return;
        }// end function

        private function clickHandler(event:MouseEvent) : void
        {
            var _loc_2:GroupCopyLeaveOperData = null;
            if (event.target == this._btnCreateCopy)
            {
                if (GameController.arena.isMatching)
                {
                    Alert.show(Language.getStringByParam(70904, _tcopy.name), null, Alert.OK | Alert.CANCEL, null, this.createGroup);
                    return;
                }
                if (GameController.copy.heroArenaCopy.isMatching)
                {
                    Alert.show(Language.getStringByParam(70905, _tcopy.name), null, Alert.OK | Alert.CANCEL, null, this.createGroup);
                    return;
                }
                Dispatcher.dispatchEvent(new DataEvent(EventName.CopyGroupCreate, _tcopy));
            }
            else if (event.target == this._btnFastEnterGroup)
            {
                if (Cache.instance.group.isInGroup)
                {
                    _loc_2 = new GroupCopyLeaveOperData(GroupCopyLeaveOperData.FastEnterGroup);
                    _loc_2.tcopy = _tcopy;
                    Dispatcher.dispatchEvent(new DataEvent(EventName.GroupLeave, _loc_2));
                    return;
                }
                if (Cache.instance.group.groupCopyEnterNum >= _tcopy.dayNum)
                {
                    return MsgManager.showRollTipsMsg(Language.getString(30808));
                }
                if (Cache.instance.role.entityInfo.level < _tcopy.enterMinLevel || Cache.instance.role.entityInfo.level > _tcopy.enterMaxLevel)
                {
                    return MsgManager.showRollTipsMsg(Language.getString(30809));
                }
                if (GameController.arena.isMatching)
                {
                    Alert.show(Language.getStringByParam(70906, _tcopy.name), null, Alert.OK | Alert.CANCEL, null, this.fastEnterCopy);
                    return;
                }
                Dispatcher.dispatchEvent(new DataEvent(EventName.CopyGroupQuickReq, _tcopy));
            }
            else if (event.target == this._btnRefresh)
            {
                this.getCopyGroupList();
            }
            return;
        }// end function

        private function updateBtnEnabled(param1:Object = null) : void
        {
            if (this.isDisposed)
            {
                return;
            }
            if (!Cache.instance.group.isInGroup)
            {
                this._btnCreateCopy.enabled = true;
                this._btnFastEnterGroup.enabled = true;
            }
            else
            {
                this._btnCreateCopy.enabled = Cache.instance.group.isCaptain;
                this._btnFastEnterGroup.enabled = !Cache.instance.group.isCaptain;
            }
            return;
        }// end function

        override public function set tcopy(param1:TCopy) : void
        {
            _tcopy = param1;
            this.getCopyGroupList();
            return;
        }// end function

        public function updateGroupList(param1:SCopyWaitingGroupMsg) : void
        {
            var _loc_4:Object = null;
            var _loc_6:int = 0;
            this._sgroupMsg = param1;
            var _loc_2:* = param1 ? (param1.groupInfos) : ([]);
            var _loc_3:* = new DataProvider();
            var _loc_5:* = _loc_2.length;
            this._pageSelecter.maxPage = this._sgroupMsg.pageTotal;
            while (_loc_6 < 5)
            {
                
                if (_loc_2[_loc_6])
                {
                    _loc_4 = {sgroup:_loc_2[_loc_6], tcopy:_tcopy};
                }
                else
                {
                    _loc_4 = {};
                }
                _loc_3.addItem(_loc_4);
                _loc_6++;
            }
            this._groupsList.dataProvider = _loc_3;
            return;
        }// end function

    }
}
